/**
 * 
 */
package org.wolf.core.schema;

import java.io.Serializable;

/**
 * @author 何小锋
 * 
 */
public class CopyField implements Serializable {

	private static final long serialVersionUID = 1L;

	private String source;
	private String target;
	private int maxChars;

	public CopyField(String source, String target) {
		this(source, target, 0);
	}

	public CopyField(String source, String target, int maxChars) {
		if (source == null || target == null) {
			throw new IllegalArgumentException(
					"source or target field can't be NULL.");
		}
		this.source = source;
		this.target = target;
		this.maxChars = maxChars;
	}

	public String getLimitedValue(final String value) {
		if (value == null)
			return value;
		return maxChars <= 0 || value.length() < maxChars ? value : value
				.substring(0, maxChars);
	}

	public String getSource() {
		return source;
	}

	public String getTarget() {
		return target;
	}

	public int getMaxChars() {
		return maxChars;
	}

}
